#include <gtest/gtest.h>
#include "../mqserver/mq_queue.hpp"

csjmq::MsgQueueManager::ptr mqmp;
class Queuetest : public testing::Environment
{
    virtual void SetUp() override
    {
        mqmp = std::make_shared<csjmq::MsgQueueManager>("./data/test.db");
    }

    virtual void TearDown() override
    {
        mqmp->clear();
        std::cout << "最后的清理工作" << std::endl;
    }
};

TEST(queue_test, insert_test)
{
    std::unordered_map<std::string, std::string> map = {{"k1", "v1"}};
    mqmp->declareQueue("queue1", true, false, false, map);
    mqmp->declareQueue("queue2", true, false, false, map);
    mqmp->declareQueue("queue3", true, false, false, map);
    mqmp->declareQueue("queue4", true, false, false, map);
    ASSERT_EQ(mqmp->size(), 4);
}

TEST(queue_test, select_test)
{
    csjmq::MsgQueue::ptr mqp = mqmp->selectQueue("queue1");
    ASSERT_EQ(mqp->durable, true);
    ASSERT_EQ(mqp->exclusive, false);
    ASSERT_EQ(mqmp->exists("queue1"), true);
}

TEST(queue_test, delete_test)
{
    mqmp->deleteQueue("queue1");
    csjmq::MsgQueue::ptr mqp = mqmp->selectQueue("queue1");
    ASSERT_EQ(mqp.get(), nullptr);
    ASSERT_EQ(mqmp->exists("queue1"), false);
}

int main(int argc, char *argv[])
{
    testing::AddGlobalTestEnvironment(new Queuetest);
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
